﻿using System;
using SportTraining.MVVM.View;

namespace SportTraining.MVVM.ViewModel.Impl
{
    public class ErrorPageViewModel : PageViewModel<ErrorPageViewModel>, IErrorPageViewModel
    {
        private readonly Exception exception;

        public ErrorPageViewModel(IMainWindowViewModel mainWindowViewModel) : base(mainWindowViewModel)
        {
            var error = mainWindowViewModel.GetObject(KeyConstants.ErrorKey);
            if (error != null)
            {
                exception = (Exception) error;
            }

            Back = new Command(param => mainWindowViewModel.CurrentPageUri = AppUri.MainPage);
        }

        #region Implementation of IErrorPageViewModel

        public string Message
        {
            get
            {
                if (exception == null)
                {
                    return string.Empty;
                }

                return exception.Message;
            }
        }

        public string FullMessage
        {
            get
            {
                if (exception == null)
                {
                    return string.Empty;
                }

                return exception.ToString();
            }
        }

        #endregion
    }
}